package sk.fiit.icp.event.view;

import java.util.Date;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import sk.fiit.icp.components.SignInSession;
import sk.fiit.icp.components.Utils;
import sk.fiit.icp.data.Events;
import sk.fiit.icp.data.EventsDao;
import sk.fiit.icp.data.Users;

@AuthorizeInstantiation("ADMIN")
public class EventPanel extends Panel {

	@SpringBean(name = "eventsDao")
	public EventsDao eventsDao;

	private RegistrationForm registrationForm;
	private Users user;

	public EventPanel(String id, int eventId, int window, String startT, String endT) {
		super( id );
		setOutputMarkupId( true );

		user = ((SignInSession) getSession()).getUser();
		Events event = eventsDao.findById( eventId );
		if ( event == null ) {
			Date startTime = (startT == null) ? new Date() : Utils.JSDateStringToDate( startT );
			Date endTime = (endT == null) ? new Date() : Utils.JSDateStringToDate( endT );
			event = new Events( null, null, user, null, "", startTime, endTime, "", 0, 0, 1, 0, "", null );
		}
		
		registrationForm = new RegistrationForm( "eventForm", new CompoundPropertyModel<Events>( event ), window );
		add( registrationForm );

	}

	public void setActualEvent(Events event) {
		registrationForm.setModel( new CompoundPropertyModel<Events>( event ) );
	}



}
